﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SOEI.Solution.DomainEntities.ContractManagement;

namespace SOEI.Solution.EntityFrameworkCore.EntityMapper
{
    public class ContractSummaryMapper : AbpBaseMapper, IEntityTypeConfiguration<ContractSummary>
    {
        public void Configure(EntityTypeBuilder<ContractSummary> builder)
        {
            builder.SetAttrbuteEntity();

            builder
                .HasOne(zy => zy.ContractStatus)
                .WithOne()
                .HasForeignKey<ContractSummary>(zy => zy.ContractStatusId)
                .OnDelete(DeleteBehavior.Restrict)
                .IsRequired();

            builder
                .HasIndex(zy => zy.ContractStatusId)
                .IsUnique(false);

            builder
                .HasMany(zy => zy.ContractBodys)
                .WithOne()
                .HasForeignKey(zw => zw.ContractSummaryId)
                .OnDelete(DeleteBehavior.Restrict)
                .IsRequired();

            builder
                .Property(zy => zy.CreationTime)
                .HasDefaultValueSql("sysdate");

            //builder
            //    .Property(zy => zy.Id)
            //    .ForOracleUseSequenceString("SEQ_CLFWQ_MMHT_HTDJH", 8, '0', "CL");      // 前缀 + 序列值8位(长度不够补“0”)
            
        }

    }
}
